using huqiang.Core.HGUI;
using System;
using UnityEngine;
using huqiang.UIComposite;
using huqiang.UIEvent;
using huqiang;
using huqiang.Data;
using huqiang.UIModel;
using huqiang.Core.Line;

public class HLinePage:UIPage
{
    //反射UI界面上的物体
    class View
    {
        public HLine Line;
    }
    View view;
    public override void Initial(UIElement parent, object dat = null)
    {
        base.Initial(parent, dat);
        view = LoadUI<View>("baseUI", "HLinePage");//"baseUI"创建的bytes文件名,"page"为创建的页面名
        InitialData();
        InitialEvent();
    }
    void InitialData()
    {
        Beeline beeline = new Beeline();
        beeline.lineBase.Color = Color.red;
        beeline.lineBase.Width = 2;
        beeline.Start.x = -100;
        beeline.End.x = 100;
        beeline.End.y = 100;

        ArcLine arc = new ArcLine();
        arc.Closed = true;
        arc.lineBase.Color = Color.green;
        arc.lineBase.Width = 2;
        arc.Pos = new Vector2(0, 220);
        arc.Scale = new Vector2(1, 0.6f);
        arc.Dic = 44;
        arc.Angle = 160;
        arc.Precision = 0.05f;
        arc.Radius = 300;

        BzierLine bzier = new BzierLine();
        bzier.lineBase.Color = Color.blue;
        bzier.lineBase.Width = 2;
        bzier.A = new Vector2(-11, -22);
        bzier.B = new Vector2(0, -220);
        bzier.C = new Vector2(100, 46);
        bzier.Precision = 0.04f;

        view.Line.AddLine(ref beeline);
        view.Line.AddLine(ref arc);
        view.Line.AddLine(ref bzier);
    }
    void InitialEvent()
    {
        var eve = view.Line.RegEvent<UserEvent>();
        eve.Click = (o, e) => { open = !open; rTime = 0; };
    }
    bool open;
    float rTime;
    public override void Update(float time)
    {
        if(open)
        {
            view.Line.Clear();
            rTime += time;
            rTime %= 1000;
            float r = rTime / 1000;

            Beeline beeline = new Beeline();
            beeline.lineBase.Color = Color.red;
            beeline.lineBase.Width = 10;
            beeline.Start.x = 0;
            beeline.End.x = 0;
            beeline.Start.y = -300;
            beeline.End.y =-300+ 470*r;
            view.Line.AddLine(ref beeline);
        }
    }
}
